package com.hzxy.yiyid.web.module.controller;

import com.hzxy.yiyid.web.common.base.BaseResult;
import com.hzxy.yiyid.web.common.error.ErrorCodeEnum;
import com.hzxy.yiyid.web.module.controller.Dto.MouthDto;
import com.hzxy.yiyid.web.module.repository.entity.Mouth;
import com.hzxy.yiyid.web.module.service.MouthService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api("月份查询对应的果蔬相关接口")
@RestController
@RequestMapping("/mouth")
public class MouthController {

    private static final Logger logger = LoggerFactory.getLogger(MouthController.class);
    @Autowired
    private MouthService mouthService;


    /**
     * 通过月份查找对应的果蔬
     * @param mouthDto
     * @return
     */
    @PostMapping()
    @ApiOperation(value ="通过月份名称查找对应月份的果蔬",notes = "通过月份名称查找对应月份的果蔬" )
    public BaseResult<?> getAllByMouth(@RequestBody MouthDto mouthDto){
        if(StringUtils.isBlank(mouthDto.getMouth())){
            logger.error(ErrorCodeEnum.REQUEST_PARAM_NULL_ERROR.getErrorCode(),ErrorCodeEnum.REQUEST_PARAM_NULL_ERROR.getMsg());
            return BaseResult.error(ErrorCodeEnum.REQUEST_PARAM_NULL_ERROR.getErrorCode(),ErrorCodeEnum.REQUEST_PARAM_NULL_ERROR.getMsg());
        }
        return BaseResult.success(mouthService.getAllByMouth(mouthDto));
    }

    @GetMapping("/{id}")
    @ApiOperation(value ="通过果蔬id查找对应的果蔬详细信息",notes = "通过果蔬id查找对应的果蔬详细信息" )
    public BaseResult<?> getDetailsInfoById(@PathVariable("id") Integer id){
        if(StringUtils.isBlank(id.toString())){
            logger.error(ErrorCodeEnum.REQUEST_PARAM_NULL_ERROR.getErrorCode(),ErrorCodeEnum.REQUEST_PARAM_NULL_ERROR.getMsg());
            return BaseResult.error(ErrorCodeEnum.REQUEST_PARAM_NULL_ERROR.getErrorCode(),ErrorCodeEnum.REQUEST_PARAM_NULL_ERROR.getMsg());
        }
        return mouthService.getDetailsInfoById(id);
    }


}
